<template>
    <div class="app-container">
        <div class="contentBox">
            <div class="searchBox">
                <el-form :model="queryParams" ref="queryRef" :inline="true">
                <el-form-item prop="locationId" style="margin: 0 6px 0 0;">
                    <SelectOption class="selectOptionBox" ref="locationSelectOption" selectType="multi" placeHolder="请选择区域" title="区域选择" maxSelectLength="more"
                    v-model="queryParams.locationId" @loadOptions="locationDataLoad" @chooseConfirm="handleQuery()" @clearChoose="handleQuery()" @chooseError="handleQueryError"/>
                </el-form-item>
                <el-select v-model="queryFormName" style="width: 120px" @change="changeQuerySet">
                    <el-option
                    v-for="item in queryOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                    />
                </el-select>
                <el-form-item :prop="queryFormName" style="margin: 0 6px 0 0;">
                    <el-input
                        style="width: 200px;"
                        v-model="queryParams[queryFormName]"
                        placeholder="请输入"
                        clearable
                        @keyup.enter="handleQuery()"
                    />
                </el-form-item>
                <el-form-item style="margin: 0 6px 0 0;">
                    <el-button class="normalFormBg searchBtn" icon="Search" @click="handleQuery()"></el-button>
                    <el-button class="normalFormBg searchBtn" icon="Refresh" @click="resetQuery()"></el-button>
                </el-form-item>
                </el-form>
            </div>
            <el-row :gutter="10" style="margin: 16px 0;"></el-row>
            <el-table 
                v-loading="loading"
                :data="dataList"
                border>
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column prop="date" label="日期" width="100" :show-overflow-tooltip="true" fixed="left"></el-table-column>
                <el-table-column prop="creditCode" label="物料编码" width="150"></el-table-column>
                <el-table-column prop="creditCode" label="名称" width="150"></el-table-column>
                <el-table-column label="操作" align="center" width="340" class-name="small-padding fixed-width" fixed="right">
                    <template #default="scope">
                        <div class="pageFlex pageFlexCenter" style="width: 100%;">
                        <div class="pageFlex pageFlexCenter btnSetBox" @click="handleOpenAccount(scope.row)">
                            <img src="@/assets/images/developService.png" class="img">
                            <div class="text">开户</div>
                        </div>
                        </div>
                    </template>
                </el-table-column>
		        <template #empty>
                    <el-empty description="暂无数据" style="color: var(--el-color-primary);"/>
                </template>
            </el-table>
            <div class="pageFlex pageAlignCenter pageSpaceBetween" style="margin-top: 20px;">
                <div class="totalText">共计 {{total}} 条</div>
                <el-pagination background layout="prev, pager, next" :total="total" :current-page="queryParams.pageNum" :page-size="queryParams.pageSize" @current-change="handleCurrentChange"/>
            </div>
        </div>
        <el-drawer v-model="modalShow" direction="rtl" size="600" :title="modalTitle">
            <div class="modalBox" v-if="modalShow">
                <div class="modalBoxContent">
                    <el-form
                        ref="formRef"
                        class="formContent"
                        label-width="110"
                        :model="form"
                        :rules="rules"
                    >
                        <div class="formContentTop pageFlex pageAlignCenter">
                            <div class="line"></div>
                            <div class="title">用户信息</div>
                        </div>
                        <div class="formContentCenter bgFF">
                            <el-form-item label="用户编号" prop="name"></el-form-item>
                            <el-form-item label="用户名称" prop="name"></el-form-item>
                            <el-form-item label="用户余额" prop="name"></el-form-item>
                            <el-form-item label="倍率" prop="name"></el-form-item>
                            <el-form-item label="价格类型" prop="name"></el-form-item>
                            <el-form-item label="价格" prop="name"></el-form-item>
                            <el-form-item label="表类型" prop="name"></el-form-item>
                            <el-form-item label="缴费类型" prop="name"></el-form-item>
                        </div>
                        <div class="formContentTop pageFlex pageAlignCenter">
                            <div class="line"></div>
                            <div class="title">购买输入</div>
                        </div>
                        <div class="formContentCenter bgFF">
                            <el-form-item label="支付方式" prop="name"></el-form-item>
                            <el-form-item label="输入购买金额" prop="name"></el-form-item>
                            <el-form-item label="输入购买量" prop="name"></el-form-item>
                            <el-form-item label="实际购买金额" prop="name"></el-form-item>
                            <el-form-item label="实际购买量" prop="name"></el-form-item>
                            <el-form-item label="应收金额" prop="name"></el-form-item>
                            <el-form-item label="充值序号" prop="name"></el-form-item>
                            <el-form-item>
                                <template #label>
                                    <el-text style="color: var(--el-color-error);">?</el-text>
                                    <el-text>说明</el-text>
                                </template>
                                <el-text>实收金额=应收金额+本次余额</el-text>
                            </el-form-item>
                        </div>
                    </el-form>
                </div>
                <div class="lineBox"></div>
                <div class="bottomBox pageFlex pageFlexCenter">
                <el-button type="primary" :loading="submitLoading" @click="submitNow">开户</el-button>
                </div>
                <el-button type="primary" :loading="formLoading" class="modalLoadingBox" v-if="formLoading">加载数据中</el-button>
            </div>
        </el-drawer>
    </div>
</template>
<script setup>
import { onMounted } from 'vue';
const { proxy } = getCurrentInstance();
// ---------------------------------选择区域----------------------------------
import SelectOption from '@/views/gasManage/components/SelectOption';
import { areasList } from '@/api/system/location';
function handleQueryError(e){
  proxy.$modal.msgError(e.msg)
}
async function locationDataLoad(e){
  const { node, resolve } = e;
  let id = node.level === 0 ? 0 : node.data.id;
  let data = [];
  if(node.data.isEnable != 0){
    data = await areasListApi({parentId: id});
    if(data.length){
      data.map(item=>{
        item.checked = item.isEnable == 0;
        return item
      })
    }
  }
  proxy.$refs.locationSelectOption.handleLoadApi(data, node, resolve);
}
function areasListApi(params){
  return new Promise(resolve => {
    areasList(params).then(res => {
      resolve(res.data);
    }).catch(() => {resolve(false)})
  })
}
// ---------------------------------弹窗--------------------------------
const modalShow = ref(false);
const modalTitle = ref('');
const submitLoading = ref(false);
const formLoading = ref(false);
const form = ref({});
const rules = ref({});
function handleModalShow(name){
    modalTitle.value = name;
    modalShow.value = true;
}
function submitNow(){

}
// ---------------------------------开户--------------------------------
function handleOpenAccount(row){
    handleModalShow('开户');
}
// ---------------------------------查询--------------------------------
onMounted(()=>{
  handleQuery();
})
const queryFormName = ref('name');
const preFormName = ref('name');
const queryOptions = ref([
  {
    value: 'userNo',
    label: '用户编号',
  },
  {
    value: 'name',
    label: '用户名称',
  },
  {
    value: 'doorNum',
    label: '门牌号',
  },
  {
    value: 'phone',
    label: '手机号码',
  },
  {
    value: 'address',
    label: '通信地址',
  },
  {
    value: 'meterAddress',
    label: '表地址',
  }
])
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  locationId: ''
})
const loading = ref(false);
const total = ref(0);
const dataList = ref([]);
function changeQuerySet(e){
  if(queryFormName.value !== preFormName.value){
    delete queryParams.value[preFormName.value];
    preFormName.value = e;
  }
}
function handleQuery(){
  queryParams.value.pageNum = 1;
  getList();
}
function resetQuery(){
  proxy.resetForm("queryRef");
  queryParams.value.locationId = '';
  proxy.$refs.locationSelectOption.setDefaultData();
  handleQuery();
}
function getList(){
    loading.value = true;
    setTimeout(()=>{
        dataList.value =  [1]
        loading.value = false;
    }, 1000)
}
function handleCurrentChange(e){
    queryParams.value.pageNum = e;
    getList();
}
</script>
<style lang='scss' scoped>
@import "@/assets/styles/public.scss";
:deep(.el-input){
  .el-input__wrapper{
    background-color: $formBgSet;
    box-shadow: none;
    border-radius: 0 var(--el-border-radius-base) var(--el-border-radius-base) 0;
  }
}
:deep(.el-select){
  .el-select__wrapper{
    background-color: $formBgSet;
    box-shadow: none;
    border-radius: var(--el-border-radius-base) 0 0 var(--el-border-radius-base);
  }
}
.app-container{
    width: 100%;
    min-height: calc(100vh - 66px);
    background: #F8F8F9;
    .contentBox{
        width: 100%;
        min-height: calc(100vh - $navBarHeight - 40px);
        background-color: #FFFFFF;
        border-radius: 5px;
        box-sizing: border-box;
        padding: 12px;
        .searchBox{
            .selectOptionBox{
                width: 200px;
                &:deep(.valueBox){
                border-radius: var(--el-border-radius-base);
                }
            }
            .searchBtn{
                width: 32px;
                height: 32px;
                font-size: 12px;
                padding: 0;
                border: none;
                margin: 0 6px 0 0px;
            }
        }
        .btnSetBox{
            padding: 0 10px;
            box-sizing: border-box;
            border-right: 1px solid $borderColor;
            cursor: pointer;
            .text{
                height: 16px;
                line-height: 16px;
                color: var(--el-color-primary);
            }
            .img{
                width: 16px;
                height: 16px;
                margin-right: 2px;
            }
            &:last-child{
                border-right: none;
            }
        }
        .totalText{
            height: 22px;
            font-weight: 400;
            font-size: 14px;
            color: #1D2129;
            line-height: 22px;
        }
    }
}

</style>
